#!/bin/python
import struct

def read_addr():
    with open('../.pio/build/stc8g1k08a/firmware.map') as f:
        txt = f.read()
        rf = txt.find('_SetPower ')
        lf = txt.rfind('C:', None, rf)
        return int(txt[lf+2:rf], base=16)

def gen(Kp, Ki, Kd, alpha, k, b, c_b):
    addr = read_addr()
    data = struct.pack('HHHHHHHH', Kp, Ki, Kd, alpha, addr, k, b, c_b)
    return data

data = gen(1000, 100, 100, 1000, 200, 200, 2640)
with open('eeprom.bin', 'wb') as f:
    f.write(data)
